<?php

namespace App\Admin\Exports;

use App\Model\UserMsgLog;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class GuildAccountDailyExport extends ExcelExporter implements WithMapping, WithHeadings, ShouldAutoSize
{
    //这里是导出来的文件的名字和格式
    protected $fileName = '消息记录.xlsx';
    //这里是excel的标题
    public function headings(): array
    {
        return [
            '日期',
            '代理ID',
            '代理名',
            '在线女用户',
            '收益女用户',
            '语音收入',
            '视频收入',
            '私信收入',
            '礼物收入',
            '邀请充值奖励',
            '当日结算比例',
            '推广预分成'
        ];
    }

    public function map($data): array
    {
        $baseIncome = $data->voice_income
            + $data->video_income
            + $data->msg_income
            + $data->gift_income;

        $share = $data->share_ratio == 0 ? env('GUILD_SHARE_PERCENT', 0.35) : $data->share_ratio;
        $share = round($baseIncome * $share, 2);
        return [
            $data->dt,
            $data->guildInfo->guild_id,
            $data->guildInfo->name,
            $data->active_host_num ?? 0,
            $data->income_host_num ?? 0,
            $data->voice_income ?? 0,
            $data->video_income ?? 0,
            $data->msg_income ?? 0,
            $data->gift_income ?? 0,
            $data->invite_recharge_income ?? 0,
            bcmul($data->share_ratio == 0 ? env('GUILD_SHARE_PERCENT', 0.35) : $data->share_ratio,100,2).'%',
            $share ?? 0,
        ];
    }
}
